﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Processing.js test of trim()</title>
    <script type="text/javascript" src="../../../processing.js"></script>

    <style type="text/css">
        html, body
        {
            background: #EEE;
            font-family: Arial;
            font-size: 13px;
            margin: 0;
            padding: 0;
        }
        h1
        {
            background: #385C85;
            color: #FFF;
            padding: 10px;
            padding-left: 20px;
            margin-top: 0px;
            margin-bottom: 0px;
        }
        h1 a
        {
            color: #FFF;
        }
        h2
        {
            padding-left: 20px;
        }
        p
        {
            padding-left: 20px;
            line-height: 1.3em;
        }
        p a
        {
            color: #385C85;
        }
        canvas
        {
            margin: 10px 0;
        }
        pre
        {
            margin-left: 20px;
            margin-right: 20px;
            padding: 5px;
            background: #FFF;
            border-top: 1px solid #333;
            border-bottom: 1px solid #333;
        }
        div.ref-col
        {
            float: left;
            width: 32%;
        }
    </style>
</head>
<body>
    <h1>
        <!-- name of your function and test description -->
        trim() test</h1>
    <h2>
        This is a test of trim(string)</h2>
    <p>
        trim() removes whitespace characters from the beginning and end of a String. In addition to standard whitespace characters such as space, carriage return, and tab, this function also removes the Unicode "nbsp" character.</p>
    <!-- include your processing file below -->
    <canvas datasrc="trim.pjs" width="200" height="200" style="margin-left: 10px;"></canvas>
    <img src="trim.png" alt=""/>
    <br />
    <b>Test written by <a href="http://dhodgin.wordpress.com/">Daniel Hodgin</a></b><br />
    <h1>
        Source Code:</h1>
    <pre class="brush: processing;">
// 	Trim example
size(500,220, P3D);
background(20);
stroke(128, 128, 128);
fill(64);
rect(1, 1, width-3, height-3);

String s1 = "normal string";
String s2 = "   extra leading spaces";
String s3 = "extra trailing spaces    ";
String s4 = "   both leading and trailing   ";
String[] a = { "    inconsistent ", "  spacing", "ok", "     tab at the end   	"};
String[] a2 = trim(a);

PFont font;
font = loadFont("Arial"); 
textFont(font, 14);
fill(32, 255, 0);
text("Strings", 5, 20);
text("String Arrays", 5, 120);
fill(255, 255, 255);
text("s1: |" + s1 + "|", 15, 40);
text("after: |" + trim(s1) + "|", 240, 40);
text("s2: |" + s2 + "|", 15, 60);
text("after: |" + trim(s2) + "|", 240, 60);
text("s3: |" + s3 + "|", 15, 80);
text("after: |" + trim(s3) + "|", 240, 80);
text("s4: |" + s4 + "|", 15, 100);
text("after: |" + trim(s4) + "|", 240, 100);
for(int i=0; i&lt;a2.length; i++){
  text("a[" + i + "]: |" + a[i] + "|", 15, 140+(i*20));
  text("after: |" + a2[i] + "|", 240, 140+(i*20));
}
        </pre>
    <br />
</body>
</html>
